package com.flkin.common.base;

import lombok.Builder;
import lombok.Data;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

/**
 * Ret
 *
 * @author yanxiang.huang
 */
@Data
@Builder
public class Ret {
    public static final Ret SUCCESS = new Ret(0, "success", null);
    private int code;
    private String msg;
    private Object data;

    public static Ret data(Object data) {
        return Ret.builder().data(data).msg(SUCCESS.getMsg()).build();
    }

    public static ResponseEntity<Object> ok() {
        return new ResponseEntity<>(Ret.SUCCESS, HttpStatus.OK);
    }

    public static ResponseEntity<Object> ok(Object data) {
        return new ResponseEntity<>(data(data), HttpStatus.OK);
    }

    public static ResponseEntity<Object> ok(Object data, HttpStatus status) {
        return new ResponseEntity<>(data(data), status);
    }

    public static ResponseEntity<Object> error(String msg) {
        return new ResponseEntity<>(Ret.builder().msg(msg).code(1).build(), HttpStatus.OK);
    }

    public static ResponseEntity<Object> error(String msg, int code) {
        return new ResponseEntity<>(Ret.builder().msg(msg).code(code).build(), HttpStatus.OK);
    }

    public static ResponseEntity<Object> error(String msg, int code, HttpStatus status) {
        return new ResponseEntity<>(Ret.builder().msg(msg).code(code).build(), status);
    }


}
